﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadProps
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field,
        Inherited = true, AllowMultiple = true)]
    public abstract class BaseAttribute : Attribute
    {
        protected BaseAttribute(object value)
            : this(value, null)
        {
        }

        protected BaseAttribute(object value, string key)
        {
            this.Value = value;

            if (string.IsNullOrEmpty(key))
            {
                const string ATT = "Attribute";
                var name = this.GetType().Name;
                if (!name.EndsWith(ATT))
                {
                    throw new Exception("TODO");
                }
                key = name.Substring(0, name.Length - ATT.Length);
            }
            this.Key = key;
        }

        public object Value { get; private set; }

        public string Key { get; private set; }
    }
}
